package com.zcckj.demo.common.mybatis;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * mybits-plus 自带扩展插件
 * 自动填充数据
 */
@Component
public class MybatisEntityMetaHandler implements MetaObjectHandler {


    @Override
    public void insertFill(MetaObject metaObject) {
        Date currentDate = new Date();

        this.setFieldValByName("addTime", currentDate, metaObject);
        this.setFieldValByName("lastUpdateTime", currentDate, metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("lastUpdateTime", new Date(), metaObject);
    }
}